package com.matrix.draft.sockettest.day4;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;

public class NIOClient2 {

    public static int PORT = 8080;

    public static void main(String[] args) {
        try {
            SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress(PORT));
            socketChannel.configureBlocking(false);
            while (!socketChannel.finishConnect()) {
                System.out.println("正在连接服务端中...");
            }
            socketChannel.write(ByteBuffer.wrap(("@1&你好我是Jack*").getBytes(StandardCharsets.UTF_8)));
            socketChannel.shutdownOutput();
            socketChannel.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
